package maggames.core;

/**
 * Object encompasing a single board move.  Who made the move, whose piece
 * was moved, and from-to where.
 * 
 * @author BenjaminPLee
 * @version 2.0
 */
public class GameMove {
	private Piece piece;
	private int x1;
	private int x2;
	private int y1;
	private int y2;
	
	/**
	 * Public constant signifying an off board location
	 * <br>TODO externalize
	 */
	public final static int OFFBOARD = -1;
	
	/**
	 * Default constructor which dummy values being used.
	 */
	public GameMove() {
		this.piece = Piece.NONE;
		x1 = y1 = x2 = y2 = OFFBOARD;
	}
	
	/**
	 * Builds a new GameMove object from the values of the given move object.
	 * @param move move object to be copied
	 */
	public GameMove(GameMove move) {
		this.piece = move.piece;
		this.x1 = move.x1;
		this.y1 = move.y1;
		this.x2 = move.x2;
		this.y2 = move.y2;
	}
	
	/**
	 * Utility constructor allowing for a move to be entirely created from the
	 * constructor call.
	 * 
	 * @param piece type of piece moved
	 * @param x1 original x coordinate of the moved piece
	 * @param y1 original y coordinate of the moved piece
	 * @param x2 final x coordinate of the moved piece
	 * @param y2 final y coordinate of the moved piece
	 */
	public GameMove(Piece piece, int x1, int y1, int x2, int y2) {
		this.piece = piece;
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
	
	/**
	 * Utility method to set the original point of the moved piece.
	 * 
	 * @param x original x coordinate
	 * @param y original y coordinate
	 */
	public void setFirstPoint(int x, int y) {
		this.x1 = x;
		this.y1 = y;
	}
	
	
	/**
	 * Utility method to set the original point of the moved piece.
	 * 
	 * @param x final x coordinate
	 * @param y final y coordinate
	 */
	public void setDestPoint(int x, int y) {
		this.x2 = x;
		this.y2 = y;
	}
	
	/**
	 * Returns the type of piece that was moved.
	 * 
	 * @return moved piece type
	 */
	public Piece getPiece() {
		return piece;
	}
	

	/**
	 * Sets the type of piece that was moved
	 * 
	 * @param piece moved piece type
	 */
	public void setPiece(Piece piece) {
		this.piece = piece;
	}
	

	/**
	 * @return original x coordinate
	 */
	public int getX1() {
		return x1;
	}
	

	/**
	 * @param x1 original x coordinate
	 */
	public void setX1(int x1) {
		this.x1 = x1;
	}
	

	/**
	 * @return final x coordinate
	 */
	public int getX2() {
		return x2;
	}
	

	/**
	 * @param x2 final x coordinate
	 */
	public void setX2(int x2) {
		this.x2 = x2;
	}
	

	/**
	 * @return original y coordinate
	 */
	public int getY1() {
		return y1;
	}
	

	/**
	 * @param y1 original y coordinate
	 */
	public void setY1(int y1) {
		this.y1 = y1;
	}

	/**
	 * @return final y coordinate
	 */
	public int getY2() {
		return y2;
	}

	/**
	 * @param y2 final y coordinate
	 */
	public void setY2(int y2) {
		this.y2 = y2;
	}
	
	public String toString() {
		return "Move: "+this.piece+" from ("+x1+","+y1+") to ("+x2+","+y2+")";
	}
	
	// TODO write equals method and hashmap?
}